<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-- Copyright 2016 TensorFlow authors.</span><span>
</span><span id="line-2"></span><span class="hs-comment">--</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- you may not use this file except in compliance with the License.</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- You may obtain a copy of the License at</span><span>
</span><span id="line-6"></span><span class="hs-comment">--</span><span>
</span><span id="line-7"></span><span class="hs-comment">--     http://www.apache.org/licenses/LICENSE-2.0</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Unless required by applicable law or agreed to in writing, software</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- See the License for the specific language governing permissions and</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- limitations under the License.</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-pragma">{-# LANGUAGE DeriveDataTypeable #-}</span><span>
</span><span id="line-16"></span><span class="hs-pragma">{-# LANGUAGE OverloadedStrings #-}</span><span>
</span><span id="line-17"></span><span class="hs-pragma">{-# LANGUAGE ScopedTypeVariables #-}</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">TensorFlow.Internal.FFI</span><span>
</span><span id="line-20"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorFlowException"><span class="hs-identifier">TensorFlowException</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-21"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Session"><span class="hs-identifier">Raw.Session</span></a></span><span>
</span><span id="line-22"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#withSession"><span class="hs-identifier">withSession</span></a></span><span>
</span><span id="line-23"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#extendGraph"><span class="hs-identifier">extendGraph</span></a></span><span>
</span><span id="line-24"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#run"><span class="hs-identifier">run</span></a></span><span>
</span><span id="line-25"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier">TensorData</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-26"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#setSessionConfig"><span class="hs-identifier">setSessionConfig</span></a></span><span>
</span><span id="line-27"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#setSessionTarget"><span class="hs-identifier">setSessionTarget</span></a></span><span>
</span><span id="line-28"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#getAllOpList"><span class="hs-identifier">getAllOpList</span></a></span><span>
</span><span id="line-29"></span><span>      </span><span class="annot"><span class="hs-comment">-- * Internal helper.</span></span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#useProtoAsVoidPtrLen"><span class="hs-identifier">useProtoAsVoidPtrLen</span></a></span><span>
</span><span id="line-31"></span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Concurrent.Async</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Async</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">async</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">cancel</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">waitCatch</span></span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Concurrent.MVar</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">MVar</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">modifyMVarMasked_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">newMVar</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">takeMVar</span></span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">when</span></span><span class="hs-special">)</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad.Catch</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">MonadMask</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">Exception</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">throwM</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">bracket</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">finally</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">mask_</span></span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad.IO.Class</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">MonadIO</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">liftIO</span></span><span class="hs-special">)</span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Bits</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Bits</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">toIntegralSized</span></span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Int</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Int64</span></span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Maybe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">fromMaybe</span></span><span class="hs-special">)</span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Typeable</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Typeable</span></span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Word</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Word8</span></span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Foreign</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Ptr</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">FunPtr</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">nullPtr</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">castPtr</span></span><span class="hs-special">)</span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Foreign.C.String</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">CString</span></span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Foreign.ForeignPtr</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">newForeignPtr</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">newForeignPtr_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">withForeignPtr</span></span><span class="hs-special">)</span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Foreign.Marshal.Alloc</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">free</span></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Foreign.Marshal.Array</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">withArrayLen</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">peekArray</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">mallocArray</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">copyArray</span></span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">System.IO.Unsafe</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">unsafePerformIO</span></span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.ByteString</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">B</span></span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Text</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">T</span></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Text.Encoding</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">T</span></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Text.Encoding.Error</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">T</span></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Vector.Storable</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">S</span></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.Vector.Storable.Mutable</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">M</span></span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.ProtoLens</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Message</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">encodeMessage</span></span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Proto.Tensorflow.Core.Framework.Graph</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">GraphDef</span></span><span class="hs-special">)</span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Proto.Tensorflow.Core.Framework.Types</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">DataType</span></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Proto.Tensorflow.Core.Protobuf.Config</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">ConfigProto</span></span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html"><span class="hs-identifier">TensorFlow.Internal.Raw</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Raw</span></span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span class="hs-keyword">data</span><span> </span><span id="TensorFlowException"><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorFlowException"><span class="hs-identifier hs-var">TensorFlowException</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="TensorFlowException"><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorFlowException"><span class="hs-identifier hs-var">TensorFlowException</span></a></span></span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Code"><span class="hs-identifier hs-type">Raw.Code</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">T.Text</span></span><span>
</span><span id="line-65"></span><span>    </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679163760"><span id="local-6989586621679163762"><span id="local-6989586621679163764"><span class="annot"><span class="annottext">Int -&gt; TensorFlowException -&gt; ShowS
[TensorFlowException] -&gt; ShowS
TensorFlowException -&gt; String
(Int -&gt; TensorFlowException -&gt; ShowS)
-&gt; (TensorFlowException -&gt; String)
-&gt; ([TensorFlowException] -&gt; ShowS)
-&gt; Show TensorFlowException
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [TensorFlowException] -&gt; ShowS
$cshowList :: [TensorFlowException] -&gt; ShowS
show :: TensorFlowException -&gt; String
$cshow :: TensorFlowException -&gt; String
showsPrec :: Int -&gt; TensorFlowException -&gt; ShowS
$cshowsPrec :: Int -&gt; TensorFlowException -&gt; ShowS
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></span></span></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679163755"><span id="local-6989586621679163757"><span class="annot"><span class="annottext">TensorFlowException -&gt; TensorFlowException -&gt; Bool
(TensorFlowException -&gt; TensorFlowException -&gt; Bool)
-&gt; (TensorFlowException -&gt; TensorFlowException -&gt; Bool)
-&gt; Eq TensorFlowException
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: TensorFlowException -&gt; TensorFlowException -&gt; Bool
$c/= :: TensorFlowException -&gt; TensorFlowException -&gt; Bool
== :: TensorFlowException -&gt; TensorFlowException -&gt; Bool
$c== :: TensorFlowException -&gt; TensorFlowException -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Typeable</span></span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679163746"><span id="local-6989586621679163748"><span id="local-6989586621679163750"><span class="annot"><span class="hs-identifier hs-type">Exception</span></span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorFlowException"><span class="hs-identifier hs-type">TensorFlowException</span></a></span></span></span></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- | All of the data needed to represent a tensor.</span><span>
</span><span id="line-70"></span><span class="hs-keyword">data</span><span> </span><span id="TensorData"><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-var">TensorData</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="TensorData"><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-var">TensorData</span></a></span></span><span>
</span><span id="line-71"></span><span>    </span><span class="hs-special">{</span><span> </span><span id="tensorDataDimensions"><span class="annot"><span class="annottext">TensorData -&gt; [Int64]
</span><a href="TensorFlow.Internal.FFI.html#tensorDataDimensions"><span class="hs-identifier hs-var hs-var">tensorDataDimensions</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Int64</span></span><span class="hs-special">]</span><span>
</span><span id="line-72"></span><span>    </span><span class="hs-special">,</span><span> </span><span id="tensorDataType"><span class="annot"><span class="annottext">TensorData -&gt; DataType
</span><a href="TensorFlow.Internal.FFI.html#tensorDataType"><span class="hs-identifier hs-var hs-var">tensorDataType</span></a></span></span><span>       </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="annot"><span class="hs-identifier hs-type">DataType</span></span><span>
</span><span id="line-73"></span><span>    </span><span class="hs-special">,</span><span> </span><span id="tensorDataBytes"><span class="annot"><span class="annottext">TensorData -&gt; Vector Word8
</span><a href="TensorFlow.Internal.FFI.html#tensorDataBytes"><span class="hs-identifier hs-var hs-var">tensorDataBytes</span></a></span></span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">S.Vector</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Word8</span></span><span class="hs-special">)</span><span>
</span><span id="line-74"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-75"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679163735"><span id="local-6989586621679163737"><span id="local-6989586621679163739"><span class="annot"><span class="annottext">Int -&gt; TensorData -&gt; ShowS
[TensorData] -&gt; ShowS
TensorData -&gt; String
(Int -&gt; TensorData -&gt; ShowS)
-&gt; (TensorData -&gt; String)
-&gt; ([TensorData] -&gt; ShowS)
-&gt; Show TensorData
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [TensorData] -&gt; ShowS
$cshowList :: [TensorData] -&gt; ShowS
show :: TensorData -&gt; String
$cshow :: TensorData -&gt; String
showsPrec :: Int -&gt; TensorData -&gt; ShowS
$cshowsPrec :: Int -&gt; TensorData -&gt; ShowS
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></span></span></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679163731"><span id="local-6989586621679163733"><span class="annot"><span class="annottext">TensorData -&gt; TensorData -&gt; Bool
(TensorData -&gt; TensorData -&gt; Bool)
-&gt; (TensorData -&gt; TensorData -&gt; Bool) -&gt; Eq TensorData
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: TensorData -&gt; TensorData -&gt; Bool
$c/= :: TensorData -&gt; TensorData -&gt; Bool
== :: TensorData -&gt; TensorData -&gt; Bool
$c== :: TensorData -&gt; TensorData -&gt; Bool
</span><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></span></span></span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-comment">-- | Runs the given action after creating a session with options</span><span>
</span><span id="line-78"></span><span class="hs-comment">-- populated by the given optionSetter.</span><span>
</span><span id="line-79"></span><span id="local-6989586621679163729"><span id="local-6989586621679163730"><span class="annot"><a href="TensorFlow.Internal.FFI.html#withSession"><span class="hs-identifier hs-type">withSession</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">MonadIO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163730"><span class="hs-identifier hs-type">m</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MonadMask</span></span><span> </span><span class="annot"><a href="#local-6989586621679163730"><span class="hs-identifier hs-type">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-80"></span><span>            </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Internal.Raw.html#SessionOptions"><span class="hs-identifier hs-type">Raw.SessionOptions</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-81"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Session"><span class="hs-identifier hs-type">Raw.Session</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679163730"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679163729"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-82"></span><span>            </span><span class="hs-comment">-- ^ The action can spawn concurrent tasks which will</span><span>
</span><span id="line-83"></span><span>            </span><span class="hs-comment">-- be canceled before withSession returns.</span><span>
</span><span id="line-84"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679163730"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679163729"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-85"></span><span id="withSession"><span class="annot"><span class="annottext">withSession :: (SessionOptions -&gt; IO ())
-&gt; ((IO () -&gt; IO ()) -&gt; Session -&gt; m a) -&gt; m a
</span><a href="TensorFlow.Internal.FFI.html#withSession"><span class="hs-identifier hs-var hs-var">withSession</span></a></span></span><span> </span><span id="local-6989586621679163728"><span class="annot"><span class="annottext">optionSetter :: SessionOptions -&gt; IO ()
</span><a href="#local-6989586621679163728"><span class="hs-identifier hs-var">optionSetter</span></a></span></span><span> </span><span id="local-6989586621679163727"><span class="annot"><span class="annottext">action :: (IO () -&gt; IO ()) -&gt; Session -&gt; m a
</span><a href="#local-6989586621679163727"><span class="hs-identifier hs-var">action</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-86"></span><span>    </span><span id="local-6989586621679163726"><span class="annot"><span class="annottext">MVar [Async ()]
</span><a href="#local-6989586621679163726"><span class="hs-identifier hs-var">drain</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (MVar [Async ()]) -&gt; m (MVar [Async ()])
forall (m :: * -&gt; *) a. MonadIO m =&gt; IO a -&gt; m a
</span><span class="hs-identifier hs-var">liftIO</span></span><span> </span><span class="annot"><span class="annottext">(IO (MVar [Async ()]) -&gt; m (MVar [Async ()]))
-&gt; IO (MVar [Async ()]) -&gt; m (MVar [Async ()])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Async ()] -&gt; IO (MVar [Async ()])
forall a. a -&gt; IO (MVar a)
</span><span class="hs-identifier hs-var">newMVar</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679163725"><span class="annot"><span class="annottext">cleanup :: Session -&gt; IO ()
</span><a href="#local-6989586621679163725"><span class="hs-identifier hs-var hs-var">cleanup</span></a></span></span><span> </span><span id="local-6989586621679163724"><span class="annot"><span class="annottext">s :: Session
</span><a href="#local-6989586621679163724"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-88"></span><span>        </span><span class="hs-comment">-- Closes the session to nudge the pending run calls to fail and exit.</span><span>
</span><span id="line-89"></span><span>            </span><span class="annot"><span class="annottext">IO () -&gt; IO () -&gt; IO ()
forall (m :: * -&gt; *) a b. MonadMask m =&gt; m a -&gt; m b -&gt; m a
</span><span class="hs-identifier hs-var">finally</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Status -&gt; IO ()) -&gt; IO ()
forall a. (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var">checkStatus</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Session -&gt; Status -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#closeSession"><span class="hs-identifier hs-var">Raw.closeSession</span></a></span><span> </span><span class="annot"><span class="annottext">Session
</span><a href="#local-6989586621679163724"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-90"></span><span>                </span><span id="local-6989586621679163721"><span class="annot"><span class="annottext">[Async ()]
</span><a href="#local-6989586621679163721"><span class="hs-identifier hs-var">runners</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar [Async ()] -&gt; IO [Async ()]
forall a. MVar a -&gt; IO a
</span><span class="hs-identifier hs-var">takeMVar</span></span><span> </span><span class="annot"><span class="annottext">MVar [Async ()]
</span><a href="#local-6989586621679163726"><span class="hs-identifier hs-var">drain</span></a></span><span>
</span><span id="line-91"></span><span>                </span><span class="hs-comment">-- Collects all runners before deleting the session.</span><span>
</span><span id="line-92"></span><span>                </span><span class="annot"><span class="annottext">(Async () -&gt; IO ()) -&gt; [Async ()] -&gt; IO ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><span class="hs-identifier hs-var">mapM_</span></span><span> </span><span class="annot"><span class="annottext">Async () -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#shutDownRunner"><span class="hs-identifier hs-var">shutDownRunner</span></a></span><span> </span><span class="annot"><span class="annottext">[Async ()]
</span><a href="#local-6989586621679163721"><span class="hs-identifier hs-var">runners</span></a></span><span>
</span><span id="line-93"></span><span>                </span><span class="annot"><span class="annottext">(Status -&gt; IO ()) -&gt; IO ()
forall a. (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var">checkStatus</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Session -&gt; Status -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#deleteSession"><span class="hs-identifier hs-var">Raw.deleteSession</span></a></span><span> </span><span class="annot"><span class="annottext">Session
</span><a href="#local-6989586621679163724"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-94"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679163717"><span class="annot"><span class="annottext">bracketIO :: IO a -&gt; (a -&gt; IO c) -&gt; (a -&gt; m b) -&gt; m b
</span><a href="#local-6989586621679163717"><span class="hs-identifier hs-var hs-var">bracketIO</span></a></span></span><span> </span><span id="local-6989586621679163716"><span class="annot"><span class="annottext">x :: IO a
</span><a href="#local-6989586621679163716"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679163715"><span class="annot"><span class="annottext">y :: a -&gt; IO c
</span><a href="#local-6989586621679163715"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m a -&gt; (a -&gt; m c) -&gt; (a -&gt; m b) -&gt; m b
forall (m :: * -&gt; *) a c b.
MonadMask m =&gt;
m a -&gt; (a -&gt; m c) -&gt; (a -&gt; m b) -&gt; m b
</span><span class="hs-identifier hs-var">bracket</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO a -&gt; m a
forall (m :: * -&gt; *) a. MonadIO m =&gt; IO a -&gt; m a
</span><span class="hs-identifier hs-var">liftIO</span></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679163716"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO c -&gt; m c
forall (m :: * -&gt; *) a. MonadIO m =&gt; IO a -&gt; m a
</span><span class="hs-identifier hs-var">liftIO</span></span><span> </span><span class="annot"><span class="annottext">(IO c -&gt; m c) -&gt; (a -&gt; IO c) -&gt; a -&gt; m c
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; IO c
</span><a href="#local-6989586621679163715"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-95"></span><span>    </span><span class="annot"><span class="annottext">IO SessionOptions
-&gt; (SessionOptions -&gt; IO ()) -&gt; (SessionOptions -&gt; m a) -&gt; m a
forall (m :: * -&gt; *) a c b.
(MonadMask m, MonadIO m) =&gt;
IO a -&gt; (a -&gt; IO c) -&gt; (a -&gt; m b) -&gt; m b
</span><a href="#local-6989586621679163717"><span class="hs-identifier hs-var">bracketIO</span></a></span><span> </span><span class="annot"><span class="annottext">IO SessionOptions
</span><a href="TensorFlow.Internal.Raw.html#newSessionOptions"><span class="hs-identifier hs-var">Raw.newSessionOptions</span></a></span><span> </span><span class="annot"><span class="annottext">SessionOptions -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#deleteSessionOptions"><span class="hs-identifier hs-var">Raw.deleteSessionOptions</span></a></span><span> </span><span class="annot"><span class="annottext">((SessionOptions -&gt; m a) -&gt; m a) -&gt; (SessionOptions -&gt; m a) -&gt; m a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163711"><span class="annot"><span class="annottext">options :: SessionOptions
</span><a href="#local-6989586621679163711"><span class="hs-identifier hs-var">options</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-96"></span><span>        </span><span class="annot"><span class="annottext">IO Session -&gt; (Session -&gt; IO ()) -&gt; (Session -&gt; m a) -&gt; m a
forall (m :: * -&gt; *) a c b.
(MonadMask m, MonadIO m) =&gt;
IO a -&gt; (a -&gt; IO c) -&gt; (a -&gt; m b) -&gt; m b
</span><a href="#local-6989586621679163717"><span class="hs-identifier hs-var">bracketIO</span></a></span><span>
</span><span id="line-97"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SessionOptions -&gt; IO ()
</span><a href="#local-6989586621679163728"><span class="hs-identifier hs-var">optionSetter</span></a></span><span> </span><span class="annot"><span class="annottext">SessionOptions
</span><a href="#local-6989586621679163711"><span class="hs-identifier hs-var">options</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO Session -&gt; IO Session
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><span class="hs-operator hs-var">&gt;&gt;</span></span><span> </span><span class="annot"><span class="annottext">(Status -&gt; IO Session) -&gt; IO Session
forall a. (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var">checkStatus</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SessionOptions -&gt; Status -&gt; IO Session
</span><a href="TensorFlow.Internal.Raw.html#newSession"><span class="hs-identifier hs-var">Raw.newSession</span></a></span><span> </span><span class="annot"><span class="annottext">SessionOptions
</span><a href="#local-6989586621679163711"><span class="hs-identifier hs-var">options</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span>            </span><span class="annot"><span class="annottext">Session -&gt; IO ()
</span><a href="#local-6989586621679163725"><span class="hs-identifier hs-var">cleanup</span></a></span><span>
</span><span id="line-99"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; Session -&gt; m a
</span><a href="#local-6989586621679163727"><span class="hs-identifier hs-var">action</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MVar [Async ()] -&gt; IO () -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#asyncCollector"><span class="hs-identifier hs-var">asyncCollector</span></a></span><span> </span><span class="annot"><span class="annottext">MVar [Async ()]
</span><a href="#local-6989586621679163726"><span class="hs-identifier hs-var">drain</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#asyncCollector"><span class="hs-identifier hs-type">asyncCollector</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MVar</span></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">Async</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-102"></span><span id="asyncCollector"><span class="annot"><span class="annottext">asyncCollector :: MVar [Async ()] -&gt; IO () -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#asyncCollector"><span class="hs-identifier hs-var hs-var">asyncCollector</span></a></span></span><span> </span><span id="local-6989586621679163708"><span class="annot"><span class="annottext">drain :: MVar [Async ()]
</span><a href="#local-6989586621679163708"><span class="hs-identifier hs-var">drain</span></a></span></span><span> </span><span id="local-6989586621679163707"><span class="annot"><span class="annottext">runner :: IO ()
</span><a href="#local-6989586621679163707"><span class="hs-identifier hs-var">runner</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">MVar [Async ()] -&gt; ([Async ()] -&gt; IO [Async ()]) -&gt; IO ()
forall a. MVar a -&gt; (a -&gt; IO a) -&gt; IO ()
</span><span class="hs-identifier hs-var">modifyMVarMasked_</span></span><span> </span><span class="annot"><span class="annottext">MVar [Async ()]
</span><a href="#local-6989586621679163708"><span class="hs-identifier hs-var">drain</span></a></span><span> </span><span class="annot"><span class="annottext">[Async ()] -&gt; IO [Async ()]
</span><a href="#local-6989586621679163706"><span class="hs-identifier hs-var">launchAndRecord</span></a></span><span>
</span><span id="line-103"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-104"></span><span>      </span><span id="local-6989586621679163706"><span class="annot"><span class="annottext">launchAndRecord :: [Async ()] -&gt; IO [Async ()]
</span><a href="#local-6989586621679163706"><span class="hs-identifier hs-var hs-var">launchAndRecord</span></a></span></span><span> </span><span id="local-6989586621679163705"><span class="annot"><span class="annottext">restRunners :: [Async ()]
</span><a href="#local-6989586621679163705"><span class="hs-identifier hs-var">restRunners</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Async () -&gt; [Async ()] -&gt; [Async ()]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[Async ()]
</span><a href="#local-6989586621679163705"><span class="hs-identifier hs-var">restRunners</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Async () -&gt; [Async ()]) -&gt; IO (Async ()) -&gt; IO [Async ()]
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO (Async ())
forall a. IO a -&gt; IO (Async a)
</span><span class="hs-identifier hs-var">async</span></span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679163707"><span class="hs-identifier hs-var">runner</span></a></span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#shutDownRunner"><span class="hs-identifier hs-type">shutDownRunner</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Async</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span id="shutDownRunner"><span class="annot"><span class="annottext">shutDownRunner :: Async () -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#shutDownRunner"><span class="hs-identifier hs-var hs-var">shutDownRunner</span></a></span></span><span> </span><span id="local-6989586621679163703"><span class="annot"><span class="annottext">r :: Async ()
</span><a href="#local-6989586621679163703"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-108"></span><span>    </span><span class="annot"><span class="annottext">Async () -&gt; IO ()
forall a. Async a -&gt; IO ()
</span><span class="hs-identifier hs-var">cancel</span></span><span> </span><span class="annot"><span class="annottext">Async ()
</span><a href="#local-6989586621679163703"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-109"></span><span>    </span><span class="hs-comment">-- TODO(gnezdo): manage exceptions better than print.</span><span>
</span><span id="line-110"></span><span>    </span><span class="annot"><span class="annottext">(SomeException -&gt; IO ())
-&gt; (() -&gt; IO ()) -&gt; Either SomeException () -&gt; IO ()
forall a c b. (a -&gt; c) -&gt; (b -&gt; c) -&gt; Either a b -&gt; c
</span><span class="hs-identifier hs-var">either</span></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO ()
forall a. Show a =&gt; a -&gt; IO ()
</span><span class="hs-identifier hs-var">print</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IO () -&gt; () -&gt; IO ()
forall a b. a -&gt; b -&gt; a
</span><span class="hs-identifier hs-var">const</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><span class="hs-identifier hs-var">return</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(Either SomeException () -&gt; IO ())
-&gt; IO (Either SomeException ()) -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; (a -&gt; m b) -&gt; m a -&gt; m b
</span><span class="hs-operator hs-var">=&lt;&lt;</span></span><span> </span><span class="annot"><span class="annottext">Async () -&gt; IO (Either SomeException ())
forall a. Async a -&gt; IO (Either SomeException a)
</span><span class="hs-identifier hs-var">waitCatch</span></span><span> </span><span class="annot"><span class="annottext">Async ()
</span><a href="#local-6989586621679163703"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-111"></span><span>
</span><span id="line-112"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#extendGraph"><span class="hs-identifier hs-type">extendGraph</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Session"><span class="hs-identifier hs-type">Raw.Session</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">GraphDef</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span id="extendGraph"><span class="annot"><span class="annottext">extendGraph :: Session -&gt; GraphDef -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#extendGraph"><span class="hs-identifier hs-var hs-var">extendGraph</span></a></span></span><span> </span><span id="local-6989586621679163699"><span class="annot"><span class="annottext">session :: Session
</span><a href="#local-6989586621679163699"><span class="hs-identifier hs-var">session</span></a></span></span><span> </span><span id="local-6989586621679163698"><span class="annot"><span class="annottext">pb :: GraphDef
</span><a href="#local-6989586621679163698"><span class="hs-identifier hs-var">pb</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-114"></span><span>    </span><span class="annot"><span class="annottext">GraphDef -&gt; (Ptr () -&gt; CULong -&gt; IO ()) -&gt; IO ()
forall msg c b a.
(Message msg, Integral c, Show c, Bits c) =&gt;
msg -&gt; (Ptr b -&gt; c -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#useProtoAsVoidPtrLen"><span class="hs-identifier hs-var">useProtoAsVoidPtrLen</span></a></span><span> </span><span class="annot"><span class="annottext">GraphDef
</span><a href="#local-6989586621679163698"><span class="hs-identifier hs-var">pb</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr () -&gt; CULong -&gt; IO ()) -&gt; IO ())
-&gt; (Ptr () -&gt; CULong -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163697"><span class="annot"><span class="annottext">ptr :: Ptr ()
</span><a href="#local-6989586621679163697"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679163696"><span class="annot"><span class="annottext">len :: CULong
</span><a href="#local-6989586621679163696"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-115"></span><span>        </span><span class="annot"><span class="annottext">(Status -&gt; IO ()) -&gt; IO ()
forall a. (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var">checkStatus</span></a></span><span> </span><span class="annot"><span class="annottext">((Status -&gt; IO ()) -&gt; IO ()) -&gt; (Status -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Session -&gt; Ptr () -&gt; CULong -&gt; Status -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#extendGraph"><span class="hs-identifier hs-var">Raw.extendGraph</span></a></span><span> </span><span class="annot"><span class="annottext">Session
</span><a href="#local-6989586621679163699"><span class="hs-identifier hs-var">session</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679163697"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">CULong
</span><a href="#local-6989586621679163696"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span>
</span><span id="line-118"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#run"><span class="hs-identifier hs-type">run</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Session"><span class="hs-identifier hs-type">Raw.Session</span></a></span><span>
</span><span id="line-119"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-type">TensorData</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- ^ Feeds.</span><span>
</span><span id="line-120"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span class="hs-special">]</span><span>               </span><span class="hs-comment">-- ^ Fetches.</span><span>
</span><span id="line-121"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span class="hs-special">]</span><span>               </span><span class="hs-comment">-- ^ Targets.</span><span>
</span><span id="line-122"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-type">TensorData</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-123"></span><span id="run"><span class="annot"><span class="annottext">run :: Session
-&gt; [(ByteString, TensorData)]
-&gt; [ByteString]
-&gt; [ByteString]
-&gt; IO [TensorData]
</span><a href="TensorFlow.Internal.FFI.html#run"><span class="hs-identifier hs-var hs-var">run</span></a></span></span><span> </span><span id="local-6989586621679163694"><span class="annot"><span class="annottext">session :: Session
</span><a href="#local-6989586621679163694"><span class="hs-identifier hs-var">session</span></a></span></span><span> </span><span id="local-6989586621679163693"><span class="annot"><span class="annottext">feeds :: [(ByteString, TensorData)]
</span><a href="#local-6989586621679163693"><span class="hs-identifier hs-var">feeds</span></a></span></span><span> </span><span id="local-6989586621679163692"><span class="annot"><span class="annottext">fetches :: [ByteString]
</span><a href="#local-6989586621679163692"><span class="hs-identifier hs-var">fetches</span></a></span></span><span> </span><span id="local-6989586621679163691"><span class="annot"><span class="annottext">targets :: [ByteString]
</span><a href="#local-6989586621679163691"><span class="hs-identifier hs-var">targets</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-124"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679163690"><span class="annot"><span class="annottext">nullTensor :: Tensor
</span><a href="#local-6989586621679163690"><span class="hs-identifier hs-var hs-var">nullTensor</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Tensor -&gt; Tensor
</span><a href="TensorFlow.Internal.Raw.html#Tensor"><span class="hs-identifier hs-var">Raw.Tensor</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Tensor
forall a. Ptr a
</span><span class="hs-identifier hs-var">nullPtr</span></span><span>
</span><span id="line-125"></span><span>    </span><span class="hs-comment">-- Use mask to avoid leaking input tensors before they are passed to 'run'</span><span>
</span><span id="line-126"></span><span>    </span><span class="hs-comment">-- and output tensors before they are passed to 'createTensorData'.</span><span>
</span><span id="line-127"></span><span>    </span><span class="annot"><span class="annottext">IO [TensorData] -&gt; IO [TensorData]
forall (m :: * -&gt; *) a. MonadMask m =&gt; m a -&gt; m a
</span><span class="hs-identifier hs-var">mask_</span></span><span> </span><span class="annot"><span class="annottext">(IO [TensorData] -&gt; IO [TensorData])
-&gt; IO [TensorData] -&gt; IO [TensorData]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span>
</span><span id="line-128"></span><span>        </span><span class="hs-comment">-- Feeds</span><span>
</span><span id="line-129"></span><span>        </span><span class="annot"><span class="annottext">[ByteString]
-&gt; (Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a. [ByteString] -&gt; (Int -&gt; Ptr CString -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#withStringArrayLen"><span class="hs-identifier hs-var">withStringArrayLen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ByteString, TensorData) -&gt; ByteString
forall a b. (a, b) -&gt; a
</span><span class="hs-identifier hs-var">fst</span></span><span> </span><span class="annot"><span class="annottext">((ByteString, TensorData) -&gt; ByteString)
-&gt; [(ByteString, TensorData)] -&gt; [ByteString]
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">[(ByteString, TensorData)]
</span><a href="#local-6989586621679163693"><span class="hs-identifier hs-var">feeds</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData])
-&gt; (Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163687"><span class="annot"><span class="annottext">feedsLen :: Int
</span><a href="#local-6989586621679163687"><span class="hs-identifier hs-var">feedsLen</span></a></span></span><span> </span><span id="local-6989586621679163686"><span class="annot"><span class="annottext">feedNames :: Ptr CString
</span><a href="#local-6989586621679163686"><span class="hs-identifier hs-var">feedNames</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-130"></span><span>        </span><span class="annot"><span class="annottext">((ByteString, TensorData) -&gt; IO Tensor)
-&gt; [(ByteString, TensorData)] -&gt; IO [Tensor]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><span class="hs-identifier hs-var">mapM</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TensorData -&gt; IO Tensor
</span><a href="TensorFlow.Internal.FFI.html#createRawTensor"><span class="hs-identifier hs-var">createRawTensor</span></a></span><span> </span><span class="annot"><span class="annottext">(TensorData -&gt; IO Tensor)
-&gt; ((ByteString, TensorData) -&gt; TensorData)
-&gt; (ByteString, TensorData)
-&gt; IO Tensor
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">(ByteString, TensorData) -&gt; TensorData
forall a b. (a, b) -&gt; b
</span><span class="hs-identifier hs-var">snd</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(ByteString, TensorData)]
</span><a href="#local-6989586621679163693"><span class="hs-identifier hs-var">feeds</span></a></span><span> </span><span class="annot"><span class="annottext">IO [Tensor] -&gt; ([Tensor] -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><span class="hs-operator hs-var">&gt;&gt;=</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163683"><span class="annot"><span class="annottext">feedTensors :: [Tensor]
</span><a href="#local-6989586621679163683"><span class="hs-identifier hs-var">feedTensors</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-131"></span><span>        </span><span class="annot"><span class="annottext">[Tensor]
-&gt; (Int -&gt; Ptr Tensor -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><span class="hs-identifier hs-var">withArrayLen</span></span><span> </span><span class="annot"><span class="annottext">[Tensor]
</span><a href="#local-6989586621679163683"><span class="hs-identifier hs-var">feedTensors</span></a></span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr Tensor -&gt; IO [TensorData]) -&gt; IO [TensorData])
-&gt; (Int -&gt; Ptr Tensor -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">_</span><span> </span><span id="local-6989586621679163682"><span class="annot"><span class="annottext">cFeedTensors :: Ptr Tensor
</span><a href="#local-6989586621679163682"><span class="hs-identifier hs-var">cFeedTensors</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-132"></span><span>        </span><span class="hs-comment">-- Fetches.</span><span>
</span><span id="line-133"></span><span>        </span><span class="annot"><span class="annottext">[ByteString]
-&gt; (Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a. [ByteString] -&gt; (Int -&gt; Ptr CString -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#withStringArrayLen"><span class="hs-identifier hs-var">withStringArrayLen</span></a></span><span> </span><span class="annot"><span class="annottext">[ByteString]
</span><a href="#local-6989586621679163692"><span class="hs-identifier hs-var">fetches</span></a></span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData])
-&gt; (Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163681"><span class="annot"><span class="annottext">fetchesLen :: Int
</span><a href="#local-6989586621679163681"><span class="hs-identifier hs-var">fetchesLen</span></a></span></span><span> </span><span id="local-6989586621679163680"><span class="annot"><span class="annottext">fetchNames :: Ptr CString
</span><a href="#local-6989586621679163680"><span class="hs-identifier hs-var">fetchNames</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-134"></span><span>        </span><span class="hs-comment">-- tensorOuts is an array of null Tensor pointers that will be filled</span><span>
</span><span id="line-135"></span><span>        </span><span class="hs-comment">-- by the call to Raw.run.</span><span>
</span><span id="line-136"></span><span>        </span><span class="annot"><span class="annottext">[Tensor]
-&gt; (Int -&gt; Ptr Tensor -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><span class="hs-identifier hs-var">withArrayLen</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Tensor -&gt; [Tensor]
forall a. Int -&gt; a -&gt; [a]
</span><span class="hs-identifier hs-var">replicate</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163681"><span class="hs-identifier hs-var">fetchesLen</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163690"><span class="hs-identifier hs-var">nullTensor</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr Tensor -&gt; IO [TensorData]) -&gt; IO [TensorData])
-&gt; (Int -&gt; Ptr Tensor -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">_</span><span> </span><span id="local-6989586621679163678"><span class="annot"><span class="annottext">tensorOuts :: Ptr Tensor
</span><a href="#local-6989586621679163678"><span class="hs-identifier hs-var">tensorOuts</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-137"></span><span>        </span><span class="hs-comment">-- Targets.</span><span>
</span><span id="line-138"></span><span>        </span><span class="annot"><span class="annottext">[ByteString]
-&gt; (Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a. [ByteString] -&gt; (Int -&gt; Ptr CString -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#withStringArrayLen"><span class="hs-identifier hs-var">withStringArrayLen</span></a></span><span> </span><span class="annot"><span class="annottext">[ByteString]
</span><a href="#local-6989586621679163691"><span class="hs-identifier hs-var">targets</span></a></span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData])
-&gt; (Int -&gt; Ptr CString -&gt; IO [TensorData]) -&gt; IO [TensorData]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163677"><span class="annot"><span class="annottext">targetsLen :: Int
</span><a href="#local-6989586621679163677"><span class="hs-identifier hs-var">targetsLen</span></a></span></span><span> </span><span id="local-6989586621679163676"><span class="annot"><span class="annottext">ctargets :: Ptr CString
</span><a href="#local-6989586621679163676"><span class="hs-identifier hs-var">ctargets</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-139"></span><span>            </span><span class="annot"><span class="annottext">(Status -&gt; IO ()) -&gt; IO ()
forall a. (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var">checkStatus</span></a></span><span> </span><span class="annot"><span class="annottext">((Status -&gt; IO ()) -&gt; IO ()) -&gt; (Status -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Session
-&gt; BufferPtr
-&gt; Ptr CString
-&gt; Ptr Tensor
-&gt; CInt
-&gt; Ptr CString
-&gt; Ptr Tensor
-&gt; CInt
-&gt; Ptr CString
-&gt; CInt
-&gt; BufferPtr
-&gt; Status
-&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#run"><span class="hs-identifier hs-var">Raw.run</span></a></span><span>
</span><span id="line-140"></span><span>                </span><span class="annot"><span class="annottext">Session
</span><a href="#local-6989586621679163694"><span class="hs-identifier hs-var">session</span></a></span><span>
</span><span id="line-141"></span><span>                </span><span class="annot"><span class="annottext">BufferPtr
forall a. Ptr a
</span><span class="hs-identifier hs-var">nullPtr</span></span><span>
</span><span id="line-142"></span><span>                </span><span class="annot"><span class="annottext">Ptr CString
</span><a href="#local-6989586621679163686"><span class="hs-identifier hs-var">feedNames</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Tensor
</span><a href="#local-6989586621679163682"><span class="hs-identifier hs-var">cFeedTensors</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163687"><span class="hs-identifier hs-var">feedsLen</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-143"></span><span>                </span><span class="annot"><span class="annottext">Ptr CString
</span><a href="#local-6989586621679163680"><span class="hs-identifier hs-var">fetchNames</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Tensor
</span><a href="#local-6989586621679163678"><span class="hs-identifier hs-var">tensorOuts</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163681"><span class="hs-identifier hs-var">fetchesLen</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-144"></span><span>                </span><span class="annot"><span class="annottext">Ptr CString
</span><a href="#local-6989586621679163676"><span class="hs-identifier hs-var">ctargets</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163677"><span class="hs-identifier hs-var">targetsLen</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-145"></span><span>                </span><span class="annot"><span class="annottext">BufferPtr
forall a. Ptr a
</span><span class="hs-identifier hs-var">nullPtr</span></span><span>
</span><span id="line-146"></span><span>            </span><span class="annot"><span class="annottext">(Tensor -&gt; IO ()) -&gt; [Tensor] -&gt; IO ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><span class="hs-identifier hs-var">mapM_</span></span><span> </span><span class="annot"><span class="annottext">Tensor -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#deleteTensor"><span class="hs-identifier hs-var">Raw.deleteTensor</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor]
</span><a href="#local-6989586621679163683"><span class="hs-identifier hs-var">feedTensors</span></a></span><span>
</span><span id="line-147"></span><span>            </span><span id="local-6989586621679163672"><span class="annot"><span class="annottext">[Tensor]
</span><a href="#local-6989586621679163672"><span class="hs-identifier hs-var">outTensors</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Tensor -&gt; IO [Tensor]
forall a. Storable a =&gt; Int -&gt; Ptr a -&gt; IO [a]
</span><span class="hs-identifier hs-var">peekArray</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163681"><span class="hs-identifier hs-var">fetchesLen</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Tensor
</span><a href="#local-6989586621679163678"><span class="hs-identifier hs-var">tensorOuts</span></a></span><span>
</span><span id="line-148"></span><span>            </span><span class="annot"><span class="annottext">(Tensor -&gt; IO TensorData) -&gt; [Tensor] -&gt; IO [TensorData]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><span class="hs-identifier hs-var">mapM</span></span><span> </span><span class="annot"><span class="annottext">Tensor -&gt; IO TensorData
</span><a href="TensorFlow.Internal.FFI.html#createTensorData"><span class="hs-identifier hs-var">createTensorData</span></a></span><span> </span><span class="annot"><span class="annottext">[Tensor]
</span><a href="#local-6989586621679163672"><span class="hs-identifier hs-var">outTensors</span></a></span><span>
</span><span id="line-149"></span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="hs-comment">-- Internal.</span><span>
</span><span id="line-152"></span><span>
</span><span id="line-153"></span><span>
</span><span id="line-154"></span><span class="hs-comment">-- | Same as 'fromIntegral', but throws an error if conversion is &quot;lossy&quot;.</span><span>
</span><span id="line-155"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-type">safeConvert</span></a></span><span> </span><span class="hs-glyph">::</span><span>
</span><span id="line-156"></span><span>    </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679163868"><span class="annot"><a href="#local-6989586621679163868"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span id="local-6989586621679163867"><span class="annot"><a href="#local-6989586621679163867"><span class="hs-identifier hs-type">b</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Show</span></span><span> </span><span class="annot"><a href="#local-6989586621679163868"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Show</span></span><span> </span><span class="annot"><a href="#local-6989586621679163867"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bits</span></span><span> </span><span class="annot"><a href="#local-6989586621679163868"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bits</span></span><span> </span><span class="annot"><a href="#local-6989586621679163867"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integral</span></span><span> </span><span class="annot"><a href="#local-6989586621679163868"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integral</span></span><span> </span><span class="annot"><a href="#local-6989586621679163867"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-157"></span><span>    </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679163868"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679163867"><span class="hs-identifier hs-type">b</span></a></span><span>
</span><span id="line-158"></span><span id="safeConvert"><span class="annot"><span class="annottext">safeConvert :: a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var hs-var">safeConvert</span></a></span></span><span> </span><span id="local-6989586621679163670"><span class="annot"><span class="annottext">x :: a
</span><a href="#local-6989586621679163670"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-159"></span><span>    </span><span class="annot"><span class="annottext">b -&gt; Maybe b -&gt; b
forall a. a -&gt; Maybe a -&gt; a
</span><span class="hs-identifier hs-var">fromMaybe</span></span><span>
</span><span id="line-160"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; b
forall a. HasCallStack =&gt; String -&gt; a
</span><span class="hs-identifier hs-var">error</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-string">&quot;Failed to convert &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679163670"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span> </span><span class="annot"><span class="hs-string">&quot;, got &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; ShowS
forall a. [a] -&gt; [a] -&gt; [a]
</span><span class="hs-operator hs-var">++</span></span><span>
</span><span id="line-161"></span><span>            </span><span class="annot"><span class="annottext">b -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><span class="hs-identifier hs-var">show</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; b
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><span class="hs-identifier hs-var">fromIntegral</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679163670"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679163867"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-162"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Maybe b
forall a b.
(Integral a, Integral b, Bits a, Bits b) =&gt;
a -&gt; Maybe b
</span><span class="hs-identifier hs-var">toIntegralSized</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679163670"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span>
</span><span id="line-165"></span><span class="hs-comment">-- | Use a list of ByteString as a list of CString.</span><span>
</span><span id="line-166"></span><span id="local-6989586621679163850"><span class="annot"><a href="TensorFlow.Internal.FFI.html#withStringList"><span class="hs-identifier hs-type">withStringList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">CString</span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163850"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163850"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-167"></span><span id="withStringList"><span class="annot"><span class="annottext">withStringList :: [ByteString] -&gt; ([CString] -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#withStringList"><span class="hs-identifier hs-var hs-var">withStringList</span></a></span></span><span> </span><span id="local-6989586621679163666"><span class="annot"><span class="annottext">strings :: [ByteString]
</span><a href="#local-6989586621679163666"><span class="hs-identifier hs-var">strings</span></a></span></span><span> </span><span id="local-6989586621679163665"><span class="annot"><span class="annottext">fn :: [CString] -&gt; IO a
</span><a href="#local-6989586621679163665"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ByteString] -&gt; [CString] -&gt; IO a
</span><a href="#local-6989586621679163664"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ByteString]
</span><a href="#local-6989586621679163666"><span class="hs-identifier hs-var">strings</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-168"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-169"></span><span>    </span><span id="local-6989586621679163664"><span class="annot"><span class="annottext">go :: [ByteString] -&gt; [CString] -&gt; IO a
</span><a href="#local-6989586621679163664"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679163663"><span class="annot"><span class="annottext">cs :: [CString]
</span><a href="#local-6989586621679163663"><span class="hs-identifier hs-var">cs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[CString] -&gt; IO a
</span><a href="#local-6989586621679163665"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CString] -&gt; [CString]
forall a. [a] -&gt; [a]
</span><span class="hs-identifier hs-var">reverse</span></span><span> </span><span class="annot"><span class="annottext">[CString]
</span><a href="#local-6989586621679163663"><span class="hs-identifier hs-var">cs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-170"></span><span>    </span><span class="hs-comment">-- TODO(fmayle): Is it worth using unsafeAsCString here?</span><span>
</span><span id="line-171"></span><span>    </span><span class="annot"><a href="#local-6989586621679163664"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679163661"><span class="annot"><span class="annottext">x :: ByteString
</span><a href="#local-6989586621679163661"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679163660"><span class="annot"><span class="annottext">xs :: [ByteString]
</span><a href="#local-6989586621679163660"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679163659"><span class="annot"><span class="annottext">cs :: [CString]
</span><a href="#local-6989586621679163659"><span class="hs-identifier hs-var">cs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; (CString -&gt; IO a) -&gt; IO a
forall a. ByteString -&gt; (CString -&gt; IO a) -&gt; IO a
</span><span class="hs-identifier hs-var">B.useAsCString</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679163661"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO a) -&gt; IO a) -&gt; (CString -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163657"><span class="annot"><span class="annottext">c :: CString
</span><a href="#local-6989586621679163657"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[ByteString] -&gt; [CString] -&gt; IO a
</span><a href="#local-6989586621679163664"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[ByteString]
</span><a href="#local-6989586621679163660"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679163657"><span class="hs-identifier hs-var">c</span></a></span><span class="annot"><span class="annottext">CString -&gt; [CString] -&gt; [CString]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[CString]
</span><a href="#local-6989586621679163659"><span class="hs-identifier hs-var">cs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-172"></span><span>
</span><span id="line-173"></span><span>
</span><span id="line-174"></span><span class="hs-comment">-- | Use a list of ByteString as an array of CString.</span><span>
</span><span id="line-175"></span><span id="local-6989586621679163885"><span class="annot"><a href="TensorFlow.Internal.FFI.html#withStringArrayLen"><span class="hs-identifier hs-type">withStringArrayLen</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Ptr</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">CString</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163885"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163885"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-176"></span><span id="withStringArrayLen"><span class="annot"><span class="annottext">withStringArrayLen :: [ByteString] -&gt; (Int -&gt; Ptr CString -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#withStringArrayLen"><span class="hs-identifier hs-var hs-var">withStringArrayLen</span></a></span></span><span> </span><span id="local-6989586621679163656"><span class="annot"><span class="annottext">xs :: [ByteString]
</span><a href="#local-6989586621679163656"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span id="local-6989586621679163655"><span class="annot"><span class="annottext">fn :: Int -&gt; Ptr CString -&gt; IO a
</span><a href="#local-6989586621679163655"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ByteString] -&gt; ([CString] -&gt; IO a) -&gt; IO a
forall a. [ByteString] -&gt; ([CString] -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#withStringList"><span class="hs-identifier hs-var">withStringList</span></a></span><span> </span><span class="annot"><span class="annottext">[ByteString]
</span><a href="#local-6989586621679163656"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[CString] -&gt; (Int -&gt; Ptr CString -&gt; IO a) -&gt; IO a
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><span class="hs-operator hs-var">`withArrayLen`</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr CString -&gt; IO a
</span><a href="#local-6989586621679163655"><span class="hs-identifier hs-var">fn</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>
</span><span id="line-178"></span><span>
</span><span id="line-179"></span><span class="hs-comment">-- | Create a Raw.Tensor from a TensorData.</span><span>
</span><span id="line-180"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#createRawTensor"><span class="hs-identifier hs-type">createRawTensor</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-type">TensorData</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Tensor"><span class="hs-identifier hs-type">Raw.Tensor</span></a></span><span>
</span><span id="line-181"></span><span id="createRawTensor"><span class="annot"><span class="annottext">createRawTensor :: TensorData -&gt; IO Tensor
</span><a href="TensorFlow.Internal.FFI.html#createRawTensor"><span class="hs-identifier hs-var hs-var">createRawTensor</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-type">TensorData</span></a></span><span> </span><span id="local-6989586621679163654"><span class="annot"><span class="annottext">dims :: [Int64]
</span><a href="#local-6989586621679163654"><span class="hs-identifier hs-var">dims</span></a></span></span><span> </span><span id="local-6989586621679163653"><span class="annot"><span class="annottext">dt :: DataType
</span><a href="#local-6989586621679163653"><span class="hs-identifier hs-var">dt</span></a></span></span><span> </span><span id="local-6989586621679163652"><span class="annot"><span class="annottext">byteVec :: Vector Word8
</span><a href="#local-6989586621679163652"><span class="hs-identifier hs-var">byteVec</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-182"></span><span>    </span><span class="annot"><span class="annottext">[CInt64] -&gt; (Int -&gt; Ptr CInt64 -&gt; IO Tensor) -&gt; IO Tensor
forall a b. Storable a =&gt; [a] -&gt; (Int -&gt; Ptr a -&gt; IO b) -&gt; IO b
</span><span class="hs-identifier hs-var">withArrayLen</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Int64 -&gt; CInt64) -&gt; [Int64] -&gt; [CInt64]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="annot"><span class="annottext">Int64 -&gt; CInt64
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">[Int64]
</span><a href="#local-6989586621679163654"><span class="hs-identifier hs-var">dims</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((Int -&gt; Ptr CInt64 -&gt; IO Tensor) -&gt; IO Tensor)
-&gt; (Int -&gt; Ptr CInt64 -&gt; IO Tensor) -&gt; IO Tensor
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163651"><span class="annot"><span class="annottext">cdimsLen :: Int
</span><a href="#local-6989586621679163651"><span class="hs-identifier hs-var">cdimsLen</span></a></span></span><span> </span><span id="local-6989586621679163650"><span class="annot"><span class="annottext">cdims :: Ptr CInt64
</span><a href="#local-6989586621679163650"><span class="hs-identifier hs-var">cdims</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-183"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679163649"><span class="annot"><span class="annottext">len :: Int
</span><a href="#local-6989586621679163649"><span class="hs-identifier hs-var hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Vector Word8 -&gt; Int
forall a. Storable a =&gt; Vector a -&gt; Int
</span><span class="hs-identifier hs-var">S.length</span></span><span> </span><span class="annot"><span class="annottext">Vector Word8
</span><a href="#local-6989586621679163652"><span class="hs-identifier hs-var">byteVec</span></a></span><span>
</span><span id="line-184"></span><span>        </span><span id="local-6989586621679163647"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679163647"><span class="hs-identifier hs-var">dest</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (Ptr Word8)
forall a. Storable a =&gt; Int -&gt; IO (Ptr a)
</span><span class="hs-identifier hs-var">mallocArray</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163649"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-185"></span><span>        </span><span class="annot"><span class="annottext">Vector Word8 -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. Storable a =&gt; Vector a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><span class="hs-identifier hs-var">S.unsafeWith</span></span><span> </span><span class="annot"><span class="annottext">Vector Word8
</span><a href="#local-6989586621679163652"><span class="hs-identifier hs-var">byteVec</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Word8 -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr Word8 -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163645"><span class="annot"><span class="annottext">x :: Ptr Word8
</span><a href="#local-6989586621679163645"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><span class="hs-identifier hs-var">copyArray</span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679163647"><span class="hs-identifier hs-var">dest</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679163645"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163649"><span class="hs-identifier hs-var">len</span></a></span><span>
</span><span id="line-186"></span><span>        </span><span class="annot"><span class="annottext">DataType
-&gt; Ptr CInt64
-&gt; CInt
-&gt; Ptr ()
-&gt; CULong
-&gt; FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
-&gt; Ptr ()
-&gt; IO Tensor
</span><a href="TensorFlow.Internal.Raw.html#newTensor"><span class="hs-identifier hs-var">Raw.newTensor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; DataType
forall a. Enum a =&gt; Int -&gt; a
</span><span class="hs-identifier hs-var">toEnum</span></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; DataType) -&gt; Int -&gt; DataType
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">DataType -&gt; Int
forall a. Enum a =&gt; a -&gt; Int
</span><span class="hs-identifier hs-var">fromEnum</span></span><span> </span><span class="annot"><span class="annottext">DataType
</span><a href="#local-6989586621679163653"><span class="hs-identifier hs-var">dt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-187"></span><span>                      </span><span class="annot"><span class="annottext">Ptr CInt64
</span><a href="#local-6989586621679163650"><span class="hs-identifier hs-var">cdims</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CInt
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163651"><span class="hs-identifier hs-var">cdimsLen</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-188"></span><span>                      </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr ()
forall a b. Ptr a -&gt; Ptr b
</span><span class="hs-identifier hs-var">castPtr</span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679163647"><span class="hs-identifier hs-var">dest</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CULong
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163649"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-189"></span><span>                      </span><span class="annot"><span class="annottext">FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
</span><a href="TensorFlow.Internal.FFI.html#tensorDeallocFunPtr"><span class="hs-identifier hs-var">tensorDeallocFunPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
forall a. Ptr a
</span><span class="hs-identifier hs-var">nullPtr</span></span><span>
</span><span id="line-190"></span><span>
</span><span id="line-191"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#tensorDeallocFunPtr"><span class="hs-pragma hs-type">tensorDeallocFunPtr</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-192"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#tensorDeallocFunPtr"><span class="hs-identifier hs-type">tensorDeallocFunPtr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FunPtr</span></span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#TensorDeallocFn"><span class="hs-identifier hs-type">Raw.TensorDeallocFn</span></a></span><span>
</span><span id="line-193"></span><span id="tensorDeallocFunPtr"><span class="annot"><span class="annottext">tensorDeallocFunPtr :: FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
</span><a href="TensorFlow.Internal.FFI.html#tensorDeallocFunPtr"><span class="hs-identifier hs-var hs-var">tensorDeallocFunPtr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ()))
-&gt; FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
forall a. IO a -&gt; a
</span><span class="hs-identifier hs-var">unsafePerformIO</span></span><span> </span><span class="annot"><span class="annottext">(IO (FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ()))
 -&gt; FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ()))
-&gt; IO (FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ()))
-&gt; FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">(Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
-&gt; IO (FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ()))
</span><a href="TensorFlow.Internal.Raw.html#wrapTensorDealloc"><span class="hs-identifier hs-var">Raw.wrapTensorDealloc</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
 -&gt; IO (FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())))
-&gt; (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ())
-&gt; IO (FunPtr (Ptr () -&gt; CULong -&gt; Ptr () -&gt; IO ()))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163638"><span class="annot"><span class="annottext">x :: Ptr ()
</span><a href="#local-6989586621679163638"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; IO ()
forall a. Ptr a -&gt; IO ()
</span><span class="hs-identifier hs-var">free</span></span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679163638"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-194"></span><span>
</span><span id="line-195"></span><span class="hs-comment">-- | Create a TensorData from a Raw.Tensor.</span><span>
</span><span id="line-196"></span><span class="hs-comment">--</span><span>
</span><span id="line-197"></span><span class="hs-comment">-- Takes ownership of the Raw.Tensor.</span><span>
</span><span id="line-198"></span><span class="hs-comment">-- TODO: Currently, it just makes a copy of the Tensor (and then deletes it),</span><span>
</span><span id="line-199"></span><span class="hs-comment">-- since the raw pointer may refer to storage inside a mutable TensorFlow</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- variable.  We should avoid that copy when it's not needed; for example,</span><span>
</span><span id="line-201"></span><span class="hs-comment">-- by making TensorData wrap an IOVector, and changing the code that uses it.</span><span>
</span><span id="line-202"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#createTensorData"><span class="hs-identifier hs-type">createTensorData</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Tensor"><span class="hs-identifier hs-type">Raw.Tensor</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-type">TensorData</span></a></span><span>
</span><span id="line-203"></span><span id="createTensorData"><span class="annot"><span class="annottext">createTensorData :: Tensor -&gt; IO TensorData
</span><a href="TensorFlow.Internal.FFI.html#createTensorData"><span class="hs-identifier hs-var hs-var">createTensorData</span></a></span></span><span> </span><span id="local-6989586621679163637"><span class="annot"><span class="annottext">t :: Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-204"></span><span>    </span><span class="hs-comment">-- Read dimensions.</span><span>
</span><span id="line-205"></span><span>    </span><span id="local-6989586621679163636"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679163636"><span class="hs-identifier hs-var">numDims</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Tensor -&gt; IO CInt
</span><a href="TensorFlow.Internal.Raw.html#numDims"><span class="hs-identifier hs-var">Raw.numDims</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-206"></span><span>    </span><span id="local-6989586621679163634"><span class="annot"><span class="annottext">[CInt64]
</span><a href="#local-6989586621679163634"><span class="hs-identifier hs-var">dims</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(CInt -&gt; IO CInt64) -&gt; [CInt] -&gt; IO [CInt64]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><span class="hs-identifier hs-var">mapM</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Tensor -&gt; CInt -&gt; IO CInt64
</span><a href="TensorFlow.Internal.Raw.html#dim"><span class="hs-identifier hs-var">Raw.dim</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="hs-number">0</span></span><span class="hs-glyph">..</span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679163636"><span class="hs-identifier hs-var">numDims</span></a></span><span class="annot"><span class="annottext">CInt -&gt; CInt -&gt; CInt
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><span class="hs-glyph hs-var">-</span></span><span class="annot"><span class="hs-number">1</span></span><span class="hs-special">]</span><span>
</span><span id="line-207"></span><span>    </span><span class="hs-comment">-- Read type.</span><span>
</span><span id="line-208"></span><span>    </span><span id="local-6989586621679163632"><span class="annot"><span class="annottext">DataType
</span><a href="#local-6989586621679163632"><span class="hs-identifier hs-var">dtype</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; DataType
forall a. Enum a =&gt; Int -&gt; a
</span><span class="hs-identifier hs-var">toEnum</span></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; DataType) -&gt; (DataType -&gt; Int) -&gt; DataType -&gt; DataType
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">DataType -&gt; Int
forall a. Enum a =&gt; a -&gt; Int
</span><span class="hs-identifier hs-var">fromEnum</span></span><span> </span><span class="annot"><span class="annottext">(DataType -&gt; DataType) -&gt; IO DataType -&gt; IO DataType
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">Tensor -&gt; IO DataType
</span><a href="TensorFlow.Internal.Raw.html#tensorType"><span class="hs-identifier hs-var">Raw.tensorType</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-209"></span><span>    </span><span class="hs-comment">-- Read data.</span><span>
</span><span id="line-210"></span><span>    </span><span id="local-6989586621679163630"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163630"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CULong -&gt; Int
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">(CULong -&gt; Int) -&gt; IO CULong -&gt; IO Int
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">Tensor -&gt; IO CULong
</span><a href="TensorFlow.Internal.Raw.html#tensorByteSize"><span class="hs-identifier hs-var">Raw.tensorByteSize</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-211"></span><span>    </span><span id="local-6989586621679163628"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679163628"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr () -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><span class="hs-identifier hs-var">castPtr</span></span><span> </span><span class="annot"><span class="annottext">(Ptr () -&gt; Ptr Word8) -&gt; IO (Ptr ()) -&gt; IO (Ptr Word8)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">Tensor -&gt; IO (Ptr ())
</span><a href="TensorFlow.Internal.Raw.html#tensorData"><span class="hs-identifier hs-var">Raw.tensorData</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Ptr</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Word8</span></span><span class="hs-special">)</span><span>
</span><span id="line-212"></span><span>    </span><span id="local-6989586621679163626"><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679163626"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (ForeignPtr Word8)
forall a. Ptr a -&gt; IO (ForeignPtr a)
</span><span class="hs-identifier hs-var">newForeignPtr_</span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679163628"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-213"></span><span>    </span><span class="hs-comment">-- Make an explicit copy of the raw data, since it might point</span><span>
</span><span id="line-214"></span><span>    </span><span class="hs-comment">-- to a mutable variable's memory.</span><span>
</span><span id="line-215"></span><span>    </span><span id="local-6989586621679163625"><span class="annot"><span class="annottext">Vector Word8
</span><a href="#local-6989586621679163625"><span class="hs-identifier hs-var">v</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVector (PrimState IO) Word8 -&gt; IO (Vector Word8)
forall a (m :: * -&gt; *).
(Storable a, PrimMonad m) =&gt;
MVector (PrimState m) a -&gt; m (Vector a)
</span><span class="hs-identifier hs-var">S.freeze</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ForeignPtr Word8 -&gt; Int -&gt; MVector RealWorld Word8
forall a s. Storable a =&gt; ForeignPtr a -&gt; Int -&gt; MVector s a
</span><span class="hs-identifier hs-var">M.unsafeFromForeignPtr0</span></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Word8
</span><a href="#local-6989586621679163626"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163630"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-216"></span><span>    </span><span class="annot"><span class="annottext">Tensor -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#deleteTensor"><span class="hs-identifier hs-var">Raw.deleteTensor</span></a></span><span> </span><span class="annot"><span class="annottext">Tensor
</span><a href="#local-6989586621679163637"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-217"></span><span>    </span><span class="annot"><span class="annottext">TensorData -&gt; IO TensorData
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><span class="hs-identifier hs-var">return</span></span><span> </span><span class="annot"><span class="annottext">(TensorData -&gt; IO TensorData) -&gt; TensorData -&gt; IO TensorData
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">[Int64] -&gt; DataType -&gt; Vector Word8 -&gt; TensorData
</span><a href="TensorFlow.Internal.FFI.html#TensorData"><span class="hs-identifier hs-var">TensorData</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(CInt64 -&gt; Int64) -&gt; [CInt64] -&gt; [Int64]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><span class="hs-identifier hs-var">map</span></span><span> </span><span class="annot"><span class="annottext">CInt64 -&gt; Int64
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">[CInt64]
</span><a href="#local-6989586621679163634"><span class="hs-identifier hs-var">dims</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">DataType
</span><a href="#local-6989586621679163632"><span class="hs-identifier hs-var">dtype</span></a></span><span> </span><span class="annot"><span class="annottext">Vector Word8
</span><a href="#local-6989586621679163625"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-218"></span><span>
</span><span id="line-219"></span><span class="hs-comment">-- | Runs the given action which does FFI calls updating a provided</span><span>
</span><span id="line-220"></span><span class="hs-comment">-- status object. If the status is not OK it is thrown as</span><span>
</span><span id="line-221"></span><span class="hs-comment">-- TensorFlowException.</span><span>
</span><span id="line-222"></span><span id="local-6989586621679163937"><span class="annot"><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-type">checkStatus</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="TensorFlow.Internal.Raw.html#Status"><span class="hs-identifier hs-type">Raw.Status</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163937"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163937"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-223"></span><span id="checkStatus"><span class="annot"><span class="annottext">checkStatus :: (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var hs-var">checkStatus</span></a></span></span><span> </span><span id="local-6989586621679163622"><span class="annot"><span class="annottext">fn :: Status -&gt; IO a
</span><a href="#local-6989586621679163622"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-224"></span><span>    </span><span class="annot"><span class="annottext">IO Status -&gt; (Status -&gt; IO ()) -&gt; (Status -&gt; IO a) -&gt; IO a
forall (m :: * -&gt; *) a c b.
MonadMask m =&gt;
m a -&gt; (a -&gt; m c) -&gt; (a -&gt; m b) -&gt; m b
</span><span class="hs-identifier hs-var">bracket</span></span><span> </span><span class="annot"><span class="annottext">IO Status
</span><a href="TensorFlow.Internal.Raw.html#newStatus"><span class="hs-identifier hs-var">Raw.newStatus</span></a></span><span> </span><span class="annot"><span class="annottext">Status -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#deleteStatus"><span class="hs-identifier hs-var">Raw.deleteStatus</span></a></span><span> </span><span class="annot"><span class="annottext">((Status -&gt; IO a) -&gt; IO a) -&gt; (Status -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163619"><span class="annot"><span class="annottext">status :: Status
</span><a href="#local-6989586621679163619"><span class="hs-identifier hs-var">status</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-225"></span><span>        </span><span id="local-6989586621679163618"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679163618"><span class="hs-identifier hs-var">result</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Status -&gt; IO a
</span><a href="#local-6989586621679163622"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">Status
</span><a href="#local-6989586621679163619"><span class="hs-identifier hs-var">status</span></a></span><span>
</span><span id="line-226"></span><span>        </span><span id="local-6989586621679163617"><span class="annot"><span class="annottext">Code
</span><a href="#local-6989586621679163617"><span class="hs-identifier hs-var">code</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Status -&gt; IO Code
</span><a href="TensorFlow.Internal.Raw.html#getCode"><span class="hs-identifier hs-var">Raw.getCode</span></a></span><span> </span><span class="annot"><span class="annottext">Status
</span><a href="#local-6989586621679163619"><span class="hs-identifier hs-var">status</span></a></span><span>
</span><span id="line-227"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><span class="hs-identifier hs-var">when</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Code
</span><a href="#local-6989586621679163617"><span class="hs-identifier hs-var">code</span></a></span><span> </span><span class="annot"><span class="annottext">Code -&gt; Code -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">Code
</span><a href="TensorFlow.Internal.Raw.html#TF_OK"><span class="hs-identifier hs-var">Raw.TF_OK</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-228"></span><span>            </span><span id="local-6989586621679163613"><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679163613"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">OnDecodeError -&gt; ByteString -&gt; Text
</span><span class="hs-identifier hs-var">T.decodeUtf8With</span></span><span> </span><span class="annot"><span class="annottext">OnDecodeError
</span><span class="hs-identifier hs-var">T.lenientDecode</span></span><span> </span><span class="annot"><span class="annottext">(ByteString -&gt; Text) -&gt; IO ByteString -&gt; IO Text
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span>
</span><span id="line-229"></span><span>                   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Status -&gt; IO CString
</span><a href="TensorFlow.Internal.Raw.html#message"><span class="hs-identifier hs-var">Raw.message</span></a></span><span> </span><span class="annot"><span class="annottext">Status
</span><a href="#local-6989586621679163619"><span class="hs-identifier hs-var">status</span></a></span><span> </span><span class="annot"><span class="annottext">IO CString -&gt; (CString -&gt; IO ByteString) -&gt; IO ByteString
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><span class="hs-operator hs-var">&gt;&gt;=</span></span><span> </span><span class="annot"><span class="annottext">CString -&gt; IO ByteString
</span><span class="hs-identifier hs-var">B.packCString</span></span><span class="hs-special">)</span><span>
</span><span id="line-230"></span><span>            </span><span class="annot"><span class="annottext">TensorFlowException -&gt; IO ()
forall (m :: * -&gt; *) e a. (MonadThrow m, Exception e) =&gt; e -&gt; m a
</span><span class="hs-identifier hs-var">throwM</span></span><span> </span><span class="annot"><span class="annottext">(TensorFlowException -&gt; IO ()) -&gt; TensorFlowException -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="annot"><span class="annottext">Code -&gt; Text -&gt; TensorFlowException
</span><a href="TensorFlow.Internal.FFI.html#TensorFlowException"><span class="hs-identifier hs-var">TensorFlowException</span></a></span><span> </span><span class="annot"><span class="annottext">Code
</span><a href="#local-6989586621679163617"><span class="hs-identifier hs-var">code</span></a></span><span> </span><span class="annot"><span class="annottext">Text
</span><a href="#local-6989586621679163613"><span class="hs-identifier hs-var">msg</span></a></span><span>
</span><span id="line-231"></span><span>        </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><span class="hs-identifier hs-var">return</span></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679163618"><span class="hs-identifier hs-var">result</span></a></span><span>
</span><span id="line-232"></span><span>
</span><span id="line-233"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#setSessionConfig"><span class="hs-identifier hs-type">setSessionConfig</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ConfigProto</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#SessionOptions"><span class="hs-identifier hs-type">Raw.SessionOptions</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-234"></span><span id="setSessionConfig"><span class="annot"><span class="annottext">setSessionConfig :: ConfigProto -&gt; SessionOptions -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#setSessionConfig"><span class="hs-identifier hs-var hs-var">setSessionConfig</span></a></span></span><span> </span><span id="local-6989586621679163608"><span class="annot"><span class="annottext">pb :: ConfigProto
</span><a href="#local-6989586621679163608"><span class="hs-identifier hs-var">pb</span></a></span></span><span> </span><span id="local-6989586621679163607"><span class="annot"><span class="annottext">opt :: SessionOptions
</span><a href="#local-6989586621679163607"><span class="hs-identifier hs-var">opt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-235"></span><span>    </span><span class="annot"><span class="annottext">ConfigProto -&gt; (Ptr () -&gt; CULong -&gt; IO ()) -&gt; IO ()
forall msg c b a.
(Message msg, Integral c, Show c, Bits c) =&gt;
msg -&gt; (Ptr b -&gt; c -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#useProtoAsVoidPtrLen"><span class="hs-identifier hs-var">useProtoAsVoidPtrLen</span></a></span><span> </span><span class="annot"><span class="annottext">ConfigProto
</span><a href="#local-6989586621679163608"><span class="hs-identifier hs-var">pb</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr () -&gt; CULong -&gt; IO ()) -&gt; IO ())
-&gt; (Ptr () -&gt; CULong -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679163606"><span class="annot"><span class="annottext">ptr :: Ptr ()
</span><a href="#local-6989586621679163606"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679163605"><span class="annot"><span class="annottext">len :: CULong
</span><a href="#local-6989586621679163605"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-236"></span><span>        </span><span class="annot"><span class="annottext">(Status -&gt; IO ()) -&gt; IO ()
forall a. (Status -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#checkStatus"><span class="hs-identifier hs-var">checkStatus</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SessionOptions -&gt; Ptr () -&gt; CULong -&gt; Status -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#setConfig"><span class="hs-identifier hs-var">Raw.setConfig</span></a></span><span> </span><span class="annot"><span class="annottext">SessionOptions
</span><a href="#local-6989586621679163607"><span class="hs-identifier hs-var">opt</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><a href="#local-6989586621679163606"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">CULong
</span><a href="#local-6989586621679163605"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-237"></span><span>
</span><span id="line-238"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#setSessionTarget"><span class="hs-identifier hs-type">setSessionTarget</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="TensorFlow.Internal.Raw.html#SessionOptions"><span class="hs-identifier hs-type">Raw.SessionOptions</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-239"></span><span id="setSessionTarget"><span class="annot"><span class="annottext">setSessionTarget :: ByteString -&gt; SessionOptions -&gt; IO ()
</span><a href="TensorFlow.Internal.FFI.html#setSessionTarget"><span class="hs-identifier hs-var hs-var">setSessionTarget</span></a></span></span><span> </span><span id="local-6989586621679163603"><span class="annot"><span class="annottext">target :: ByteString
</span><a href="#local-6989586621679163603"><span class="hs-identifier hs-var">target</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; (CString -&gt; IO ()) -&gt; IO ()
forall a. ByteString -&gt; (CString -&gt; IO a) -&gt; IO a
</span><span class="hs-identifier hs-var">B.useAsCString</span></span><span> </span><span class="annot"><span class="annottext">ByteString
</span><a href="#local-6989586621679163603"><span class="hs-identifier hs-var">target</span></a></span><span> </span><span class="annot"><span class="annottext">((CString -&gt; IO ()) -&gt; IO ())
-&gt; (SessionOptions -&gt; CString -&gt; IO ()) -&gt; SessionOptions -&gt; IO ()
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><span class="hs-operator hs-var">.</span></span><span> </span><span class="annot"><span class="annottext">SessionOptions -&gt; CString -&gt; IO ()
</span><a href="TensorFlow.Internal.Raw.html#setTarget"><span class="hs-identifier hs-var">Raw.setTarget</span></a></span><span>
</span><span id="line-240"></span><span>
</span><span id="line-241"></span><span class="hs-comment">-- | Serializes the given msg and provides it as (ptr,len) argument</span><span>
</span><span id="line-242"></span><span class="hs-comment">-- to the given action.</span><span>
</span><span id="line-243"></span><span id="local-6989586621679163892"><span id="local-6989586621679163893"><span id="local-6989586621679163895"><span id="local-6989586621679163897"><span class="annot"><a href="TensorFlow.Internal.FFI.html#useProtoAsVoidPtrLen"><span class="hs-identifier hs-type">useProtoAsVoidPtrLen</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Message</span></span><span> </span><span class="annot"><a href="#local-6989586621679163897"><span class="hs-identifier hs-type">msg</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Integral</span></span><span> </span><span class="annot"><a href="#local-6989586621679163895"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Show</span></span><span> </span><span class="annot"><a href="#local-6989586621679163895"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bits</span></span><span> </span><span class="annot"><a href="#local-6989586621679163895"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span>
</span><span id="line-244"></span><span>                        </span><span class="annot"><a href="#local-6989586621679163897"><span class="hs-identifier hs-type">msg</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Ptr</span></span><span> </span><span class="annot"><a href="#local-6989586621679163893"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679163895"><span class="hs-identifier hs-type">c</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163892"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679163892"><span class="hs-identifier hs-type">a</span></a></span></span></span></span></span><span>
</span><span id="line-245"></span><span id="useProtoAsVoidPtrLen"><span class="annot"><span class="annottext">useProtoAsVoidPtrLen :: msg -&gt; (Ptr b -&gt; c -&gt; IO a) -&gt; IO a
</span><a href="TensorFlow.Internal.FFI.html#useProtoAsVoidPtrLen"><span class="hs-identifier hs-var hs-var">useProtoAsVoidPtrLen</span></a></span></span><span> </span><span id="local-6989586621679163601"><span class="annot"><span class="annottext">msg :: msg
</span><a href="#local-6989586621679163601"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span id="local-6989586621679163600"><span class="annot"><span class="annottext">f :: Ptr b -&gt; c -&gt; IO a
</span><a href="#local-6989586621679163600"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ByteString -&gt; (CStringLen -&gt; IO a) -&gt; IO a
forall a. ByteString -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><span class="hs-identifier hs-var">B.useAsCStringLen</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">msg -&gt; ByteString
forall msg. Message msg =&gt; msg -&gt; ByteString
</span><span class="hs-identifier hs-var">encodeMessage</span></span><span> </span><span class="annot"><span class="annottext">msg
</span><a href="#local-6989586621679163601"><span class="hs-identifier hs-var">msg</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((CStringLen -&gt; IO a) -&gt; IO a) -&gt; (CStringLen -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span>
</span><span id="line-246"></span><span>        </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621679163598"><span class="annot"><span class="annottext">bytes :: CString
</span><a href="#local-6989586621679163598"><span class="hs-identifier hs-var">bytes</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679163597"><span class="annot"><span class="annottext">len :: Int
</span><a href="#local-6989586621679163597"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr b -&gt; c -&gt; IO a
</span><a href="#local-6989586621679163600"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CString -&gt; Ptr b
forall a b. Ptr a -&gt; Ptr b
</span><span class="hs-identifier hs-var">castPtr</span></span><span> </span><span class="annot"><span class="annottext">CString
</span><a href="#local-6989586621679163598"><span class="hs-identifier hs-var">bytes</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; c
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679163597"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-247"></span><span>
</span><span id="line-248"></span><span class="hs-comment">-- | Returns the serialized OpList of all OpDefs defined in this</span><span>
</span><span id="line-249"></span><span class="hs-comment">-- address space.</span><span>
</span><span id="line-250"></span><span class="annot"><a href="TensorFlow.Internal.FFI.html#getAllOpList"><span class="hs-identifier hs-type">getAllOpList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span>
</span><span id="line-251"></span><span id="getAllOpList"><span class="annot"><span class="annottext">getAllOpList :: IO ByteString
</span><a href="TensorFlow.Internal.FFI.html#getAllOpList"><span class="hs-identifier hs-var hs-var">getAllOpList</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-252"></span><span>    </span><span id="local-6989586621679163596"><span class="annot"><span class="annottext">ForeignPtr Buffer
</span><a href="#local-6989586621679163596"><span class="hs-identifier hs-var">foreignPtr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-253"></span><span>        </span><span class="annot"><span class="annottext">IO (ForeignPtr Buffer) -&gt; IO (ForeignPtr Buffer)
forall (m :: * -&gt; *) a. MonadMask m =&gt; m a -&gt; m a
</span><span class="hs-identifier hs-var">mask_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FinalizerPtr Buffer -&gt; BufferPtr -&gt; IO (ForeignPtr Buffer)
forall a. FinalizerPtr a -&gt; Ptr a -&gt; IO (ForeignPtr a)
</span><span class="hs-identifier hs-var">newForeignPtr</span></span><span> </span><span class="annot"><span class="annottext">FinalizerPtr Buffer
</span><a href="TensorFlow.Internal.Raw.html#deleteBuffer"><span class="hs-identifier hs-var">Raw.deleteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(BufferPtr -&gt; IO (ForeignPtr Buffer))
-&gt; IO BufferPtr -&gt; IO (ForeignPtr Buffer)
forall (m :: * -&gt; *) a b. Monad m =&gt; (a -&gt; m b) -&gt; m a -&gt; m b
</span><span class="hs-operator hs-var">=&lt;&lt;</span></span><span> </span><span class="annot"><span class="annottext">IO BufferPtr
</span><a href="#local-6989586621679163594"><span class="hs-identifier hs-var">checkCall</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-254"></span><span>    </span><span class="hs-comment">-- Makes a copy because it is more reliable than eviscerating</span><span>
</span><span id="line-255"></span><span>    </span><span class="hs-comment">-- Buffer to steal its memory (including custom deallocator).</span><span>
</span><span id="line-256"></span><span>    </span><span class="annot"><span class="annottext">ForeignPtr Buffer -&gt; (BufferPtr -&gt; IO ByteString) -&gt; IO ByteString
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><span class="hs-identifier hs-var">withForeignPtr</span></span><span> </span><span class="annot"><span class="annottext">ForeignPtr Buffer
</span><a href="#local-6989586621679163596"><span class="hs-identifier hs-var">foreignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">((BufferPtr -&gt; IO ByteString) -&gt; IO ByteString)
-&gt; (BufferPtr -&gt; IO ByteString) -&gt; IO ByteString
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><span class="hs-operator hs-var">$</span></span><span>
</span><span id="line-257"></span><span>        </span><span class="hs-glyph">\</span><span id="local-6989586621679163593"><span class="annot"><span class="annottext">ptr :: BufferPtr
</span><a href="#local-6989586621679163593"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CStringLen -&gt; IO ByteString
</span><span class="hs-identifier hs-var">B.packCStringLen</span></span><span> </span><span class="annot"><span class="annottext">(CStringLen -&gt; IO ByteString) -&gt; IO CStringLen -&gt; IO ByteString
forall (m :: * -&gt; *) a b. Monad m =&gt; (a -&gt; m b) -&gt; m a -&gt; m b
</span><span class="hs-operator hs-var">=&lt;&lt;</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">,</span><span class="hs-special">)</span><span>
</span><span id="line-258"></span><span>                </span><span class="annot"><span class="annottext">(CString -&gt; Int -&gt; CStringLen)
-&gt; IO CString -&gt; IO (Int -&gt; CStringLen)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr () -&gt; CString
forall a b. Ptr a -&gt; Ptr b
</span><span class="hs-identifier hs-var">castPtr</span></span><span> </span><span class="annot"><span class="annottext">(Ptr () -&gt; CString) -&gt; IO (Ptr ()) -&gt; IO CString
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">BufferPtr -&gt; IO (Ptr ())
</span><a href="TensorFlow.Internal.Raw.html#getBufferData"><span class="hs-identifier hs-var">Raw.getBufferData</span></a></span><span> </span><span class="annot"><span class="annottext">BufferPtr
</span><a href="#local-6989586621679163593"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-259"></span><span>                </span><span class="annot"><span class="annottext">IO (Int -&gt; CStringLen) -&gt; IO Int -&gt; IO CStringLen
forall (f :: * -&gt; *) a b. Applicative f =&gt; f (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;*&gt;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CULong -&gt; Int
forall a b.
(Show a, Show b, Bits a, Bits b, Integral a, Integral b) =&gt;
a -&gt; b
</span><a href="TensorFlow.Internal.FFI.html#safeConvert"><span class="hs-identifier hs-var">safeConvert</span></a></span><span> </span><span class="annot"><span class="annottext">(CULong -&gt; Int) -&gt; IO CULong -&gt; IO Int
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><span class="hs-operator hs-var">&lt;$&gt;</span></span><span> </span><span class="annot"><span class="annottext">BufferPtr -&gt; IO CULong
</span><a href="TensorFlow.Internal.Raw.html#getBufferLength"><span class="hs-identifier hs-var">Raw.getBufferLength</span></a></span><span> </span><span class="annot"><span class="annottext">BufferPtr
</span><a href="#local-6989586621679163593"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-260"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-261"></span><span>      </span><span id="local-6989586621679163594"><span class="annot"><span class="annottext">checkCall :: IO BufferPtr
</span><a href="#local-6989586621679163594"><span class="hs-identifier hs-var hs-var">checkCall</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-262"></span><span>          </span><span id="local-6989586621679163589"><span class="annot"><span class="annottext">BufferPtr
</span><a href="#local-6989586621679163589"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO BufferPtr
</span><a href="TensorFlow.Internal.Raw.html#getAllOpList"><span class="hs-identifier hs-var">Raw.getAllOpList</span></a></span><span>
</span><span id="line-263"></span><span>          </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><span class="hs-identifier hs-var">when</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">BufferPtr
</span><a href="#local-6989586621679163589"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">BufferPtr -&gt; BufferPtr -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">BufferPtr
forall a. Ptr a
</span><span class="hs-identifier hs-var">nullPtr</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TensorFlowException -&gt; IO ()
forall (m :: * -&gt; *) e a. (MonadThrow m, Exception e) =&gt; e -&gt; m a
</span><span class="hs-identifier hs-var">throwM</span></span><span> </span><span class="annot"><span class="annottext">TensorFlowException
</span><a href="#local-6989586621679163587"><span class="hs-identifier hs-var">exception</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-264"></span><span>          </span><span class="annot"><span class="annottext">BufferPtr -&gt; IO BufferPtr
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><span class="hs-identifier hs-var">return</span></span><span> </span><span class="annot"><span class="annottext">BufferPtr
</span><a href="#local-6989586621679163589"><span class="hs-identifier hs-var">p</span></a></span><span>
</span><span id="line-265"></span><span>      </span><span id="local-6989586621679163587"><span class="annot"><span class="annottext">exception :: TensorFlowException
</span><a href="#local-6989586621679163587"><span class="hs-identifier hs-var hs-var">exception</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Code -&gt; Text -&gt; TensorFlowException
</span><a href="TensorFlow.Internal.FFI.html#TensorFlowException"><span class="hs-identifier hs-var">TensorFlowException</span></a></span><span>
</span><span id="line-266"></span><span>                </span><span class="annot"><span class="annottext">Code
</span><a href="TensorFlow.Internal.Raw.html#TF_UNKNOWN"><span class="hs-identifier hs-var">Raw.TF_UNKNOWN</span></a></span><span> </span><span class="annot"><span class="hs-string">&quot;GetAllOpList failure, check logs&quot;</span></span><span>
</span><span id="line-267"></span></pre></body></html>